package louie.wendy.bootswagger.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import louie.wendy.bootswagger.model.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = {"user API:"})

@RestController
@RequestMapping(value = "/user")
public class DemoController {

    @ApiOperation(value = "获取用户", notes = "获取用户详细信息")
    @ApiImplicitParam(name = "userId", value = "user's primary key", required = true)

    @GetMapping(value = "/{userId}")
    public User detail (@PathVariable String userId) {
        return new User(){{
            setUserId(userId);
            setName("jack");
            setAge(18);
        }};
    }

    @ApiOperation(value = "获取角色用户", notes = "根据角色获取用户列表", responseContainer = "List", response = User.class)
    @ApiImplicitParam(name = "roleId", value = "role's primary key", required = true)

    @GetMapping(value = "/role")
    public List<User> roleUser (String roleId) {
        return new ArrayList<>();
    }

    @ApiOperation(value = "新建用户", notes = "创建新用户", response = String.class)

    @PostMapping
    public ResponseEntity<String> create (@ApiParam(value = "new user info", required = true) @RequestBody User user) {
        return new ResponseEntity<>("user created", HttpStatus.OK);
    }

    @ApiOperation(value = "更新用户", notes = "更新用户信息", response = String.class)
    @ApiImplicitParam(name = "user", value = "user's information", required = true, paramType = "body", dataType = "user model")

    @PutMapping
    public ResponseEntity<String> update (@RequestBody User user) {
        return new ResponseEntity<>("user updated", HttpStatus.OK);
    }

    @ApiOperation(value = "删除用户", notes = "删除指定用户", response = String.class)
    @ApiImplicitParam(name = "userId", value = "user's primary key", required = true)

    @DeleteMapping(value = "/{userId}")
    public ResponseEntity<String> delete (@PathVariable String userId) {
        return new ResponseEntity<>("user deleted, user's primary key is: " + userId, HttpStatus.OK);
    }
}
